package com.foreknow.Servlet;

import com.foreknow.entity.User;
import com.foreknow.service.UserService;
import com.foreknow.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "AddServlet" ,urlPatterns = "/Add")
public class AddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        String username =request.getParameter("username");
        String password = request.getParameter("password");
      String account= request.getParameter("account");
        String phone =request.getParameter("phone");
        String email=request.getParameter("email");
        String avatar=request.getParameter("avatar");
        UserService service=new UserServiceImpl();
        User user =new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setAvatar(avatar);
        user.setAccount(account);
        user.setPhone(phone);
        user.setEmail(email);
       boolean isRight= service.add(user);
       if (isRight){
           out.println("添加成功");
       }else {
           out.println("添加失败");
       }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
